package com.gec.it.controller;


import com.gec.it.entity.Depts;
import com.gec.it.service.DeptsService;
import com.gec.it.util.EmailUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 雄哥爱吃肉
 * @since 2022-01-04
 */
@Controller
@RequestMapping("/depts")
public class DeptsController {
    @Autowired
    private DeptsService service;

    @RequiresPermissions("dept:add")
    @GetMapping("/add")
    public String add(){
        return "dept_add";
    }
    @PostMapping("/add")
    public String add(Depts d){
        service.save(d);
        return "redirect:list";
    }
    @RequiresPermissions("dept:list")
    @GetMapping("/list")
    public String list(Model m){
        List<Depts> list =service.list2();
        m.addAttribute("list",list);
        return "dept_list";
    }
    @RequiresPermissions("dept:edit")
    @GetMapping("/edit")
    public String edit(int deptid,Model m){
        Depts depts=service.getById2(deptid);
        m.addAttribute("dept",depts);
        return "dept_edit";
    }
    @PostMapping("/edit")
    public String edit(Depts dept){
        service.updateById(dept);
        return "redirect:list";
    }
    @RequiresPermissions("dept:del")
    @GetMapping("/del")
    public String del(int deptid){
        service.removeById(deptid);
        return "redirect:list";
    }
}
